def is_prime(num):
    if num < 2:
        return False
    for i in range(2, int(num**0.5) + 1):
        if num % i == 0:
            return False
    return True

def next_prime(num):
    prime = num
    while True:
        prime += 1
        if is_prime(prime):
            return prime

def previous_prime(num):
    prime = num
    while prime > 1:
        prime -= 1
        if is_prime(prime):
            return prime

def closest_prime(num):
    next_p = next_prime(num)
    prev_p = previous_prime(num)
    if num - prev_p <= next_p - num:
        return prev_p
    else:
        return next_p

words_to_numbers = {
    'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4,
    'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9
}

def words_to_number(words):
    digits = words.split()
    if len(digits) != 3:
        return "Wrong input"
    try:
        number = 100*words_to_numbers[digits[0]] + 10*words_to_numbers[digits[1]] + words_to_numbers[digits[2]]
        return number
    except KeyError:
        return "Wrong input"

input_words = input("Введите три слова, представляющие цифры: ")
number = words_to_number(input_words)
if isinstance(number, int):
    print(closest_prime(number))
else:
    print(number)